package com.yyl.rbacs.sys.controller;

import com.yyl.rbacs.annotation.OperationLog;
import com.yyl.rbacs.sys.entity.SysRole;
import com.yyl.rbacs.sys.service.ISysRoleService;
import com.yyl.rbacs.utils.PageVo;
import com.yyl.rbacs.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 角色 前端控制器
 * </p>
 *
 * @author YuanSir
 * @since 2022-10-28
 */
@RestController
@RequestMapping("/sys/role")
public class SysRoleController {
    
    @Autowired
    private ISysRoleService roleService;
    
    @GetMapping("/list")
    @RequiresPermissions("sys:role:list")
    public R roleList(@RequestParam Map<String, String> params){
        
        PageVo pageVo = roleService.queryPage(params);
        
        return R.ok("显示成功！").put("page", pageVo);
        
    }
    
    @PostMapping("/save")
    public R save(@RequestBody SysRole sysRole){
        
        roleService.saveRole(sysRole);
    
        return R.ok();
    
    }
    
    
    @GetMapping("/info/{roleId}")
    public R info(@PathVariable("roleId") Long roleId){
    
        SysRole role = roleService.getRoleById(roleId);
    
        return R.ok().put("role", role);
    
    }
    
    
    @PostMapping("/update")
    public R update(@RequestBody SysRole sysRole){
        
        roleService.updateRole(sysRole);
        
        return R.ok();
        
    }
    
    
}
